$(document).ajaxError(function(event, xhr, options, exc) {
    console.log(xhr.status);
});
//设置模态框样式
//$(".modal-content").css({"height":$(window).height()-60});
//$(window).resize(function(){
//    $(".modal-content").css("height",$(window).height()-60);
//});

//选择所有checkbox元素下所有的表单元素
function checkedAllIDS(obj) {
    var checkedAllIDS = "";
    obj.find("input").each(function(i, n) {
        checkedAllIDS += $(n).attr("data-id") + ",";
    });
    return checkedAllIDS;
}

//批量删除获取值方法，obj是子行checkbox选择器元素
function checkedIDSFUN(obj, url, dataTable) {
    var checkedIDS = "";
    var procinstid = "";
    var appliy = "";
    obj.find("input[type=checkbox]:checked").each(function(i, n) {
        checkedIDS += "," + $(n).attr("data-id");
        procinstid += $(n)
            .parents("tr")
            .find(".button-danger")
            .attr("data-procinstid");
        appliy += $(n)
            .parents("tr")
            .find(".button-danger")
            .attr("data-appliy");
    });
    var reg = /\d/;
    var isTrue = reg.test(procinstid);

    console.log(appliy.indexOf("申请人提交"));
    console.log(isTrue);
    debugger;

    if (isTrue) {
        if (
            appliy.indexOf("已完成") > -1 ||
            appliy.indexOf("经理") > -1 ||
            appliy.indexOf("部") > -1 ||
            appliy.indexOf("审批") > -1
        ) {
            Confirm.show("提示", "该工单已进入流程,不能中途删除！", {
                确定: {
                    primary: true,
                    callback: function() {
                        Confirm.hide();
                    }
                }
            });
        } else {
            deleteFun1(obj, url, dataTable, checkedIDS);
        }
    } else {
        deleteFun1(obj, url, dataTable, checkedIDS);
    }
}

function checkedIDSFUN2(obj, url, dataTable) {
    var checkedIDS = "";
    var procinstid = "";
    obj.find("input[type=checkbox]:checked").each(function(i, n) {
        checkedIDS += "," + $(n).attr("data-id");
        procinstid += $(n)
            .parents("tr")
            .find(".button-danger")
            .attr("data-status");
    });
    var reg = /\d/;
    var isTrue = reg.test(procinstid);
    if (isTrue) {
        Confirm.show("提示", "含有无法删除的供应商！", {
            确定: {
                primary: true,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
        //  	alert("改工单已进入流程,不能删除");
    } else {
        console.log(checkedIDS);
        debugger;
        deleteFunStatusSuppier(obj, url, dataTable, checkedIDS);
    }
}
//批量删除获取值方法，obj是子行checkbox选择器元素（没有工作流checkbox选择）
function checkedIDSFUNCheck(obj) {
    var checkedIDS = "";
    obj.find("input[type=checkbox]:checked").each(function(i, n) {
        checkedIDS += "," + $(n).attr("data-id");
    });
    if (checkedIDS == "") {
        return checkedIDS;
    } else {
        return checkedIDS + ",";
    }
}
//批量删除获取值方法，obj是子行checkbox选择器元素（没有工作流checkbox选择）
function checkedIDSFUNCheck1(obj) {
    var checkedIDS = "";
    var arrCheack = [];
    obj.find("input[type=checkbox]:checked").each(function(i, n) {
        checkedIDS = $(n).attr("data-id");
        arrCheack.push(checkedIDS);
    });
    //  if(checkedIDS==""){
    //      return checkedIDS;
    //  }else{
    //      return checkedIDS+",";
    //  }
    return arrCheack;
    console.log(arrCheack, "arrCheackarrCheack");
}
/*
 * 删除选中行方法
 * obj 子行checkbox选择器元素
 * url 对应的删除接口url地址
 * dataTables 定义的dataTables元素变量
 */
function deleteFun(obj, url, dataTable) {
    var procinstid = $(this).attr("data-procinstid");
    var checkedID = checkedIDSFUNCheck(obj);

    if (checkedID == 0) {
        Confirm.show("提示", "请选择删除项", {
            确定: {
                primary: true,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    } else {
        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                width: 30,
                callback: function() {
                    $.ajax({
                        type: "get",
                        url: url,
                        data: { ids: checkedID },
                        dataType: "json",
                        success: function(json) {
                            console.log("====/", json);
                            if (json.code == 200) {
                                Confirm.hide();
                                dataTable.ajax.reload();
                            }
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    }
}

/*
 * 删除选中行方法
 * obj 子行checkbox选择器元素
 * url 对应的删除接口url地址
 * dataTables 定义的dataTables元素变量
 * 状态为status
 */
//list中部分页面不能删除方法(范例参考供应商管理)
function deleteFunStatusSuppier(obj, url, dataTable, checkedIDS) {
    var procinstid = $(this).attr("data-procinstid");
    var checkedID = checkedIDSFUNCheck(obj);
    console.log("checkedID===", checkedID);
    if (checkedID == 0) {
        Confirm.show("提示", "请选择删除项", {
            确定: {
                primary: true,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    } else {
        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                width: 30,
                callback: function() {
                    $.ajax({
                        type: "get",
                        url: url,
                        data: { ids: checkedIDS },
                        dataType: "json",
                        success: function(json) {
                            console.log("====/", json);
                            if (json.status == 200) {
                                Confirm.hide();
                                dataTable.ajax.reload();
                            }
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    }
}

function deleteFunStatus(obj, url, dataTable) {
    var procinstid = $(this).attr("data-procinstid");
    var checkedID = checkedIDSFUNCheck(obj);
    console.log("checkedID===", checkedID);
    if (checkedID == 0) {
        Confirm.show("提示", "请选择删除项", {
            确定: {
                primary: true,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    } else {
        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                width: 30,
                callback: function() {
                    $.ajax({
                        type: "get",
                        url: url,
                        data: { ids: checkedID },
                        dataType: "json",
                        success: function(json) {
                            debugger;
                            console.log("====/", json);
                            if (json.status == 200) {
                                Confirm.hide();
                                dataTable.ajax.reload();
                            }
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    }
}

function deleteFunStatus1(obj, url, dataTable) {
    var procinstid = $(this).attr("data-procinstid");
    var checkedID = checkedIDSFUNCheck1(obj);
    checkedID = checkedID.join(",");
    console.log("checkedID===", checkedID);
    debugger;
    if (checkedID == 0) {
        Confirm.show("提示", "请选择删除项", {
            确定: {
                primary: true,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    } else {
        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                width: 30,
                callback: function() {
                    $.ajax({
                        type: "get",
                        url: url,
                        data: { ids: checkedID },
                        dataType: "json",
                        success: function(json) {
                            debugger;
                            console.log("====/", json);
                            if (json.status == 200) {
                                Confirm.hide();
                                dataTable.ajax.reload();
                            }
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    }
}
//删除设备
function isDel(dialog, strData) {
    $(dialog).dialog({
        resizable: false,
        height: 240,
        modal: true,
        buttons: {
            确认: function(strData) {
                $.ajax({
                    type: "get",
                    url: "/haocang-device-web/device/delete/" + strData,
                    async: true,
                    success: function(data) {
                        console.log(data);
                        if (data.status == 200) {
                            purchaseRequestDataTable.ajax.reload();
                        }
                    },
                    error: function(res) {
                        console.log("报错了==>", res);
                    }
                });
                $(this).dialog("close");
            },
            取消: function() {
                $(this).dialog("close");
            }
        }
    });
}

/*
 * 判读并删除选中行
 * obj 子行checkbox选择器元素 //$("#inventoryIn-table tbody .checkboxOne")
 * objAll 全选按钮 $(".inventoryInCheckAll")
 * url 对应的删除接口url地址    //WMS_URL + "inventoryIn/deleteMultiple"
 * dataTables 定义的dataTables元素变量 inDataTable
 */
function deleteWithStatus(obj, objAll, url, dataTable) {
    var arrCheck = []; //存储所有被选中元素id
    //获取元素的父节点上的check元素上的id
    obj.find("input[type=checkbox]:checked").each(function() {
        var _status = $(this).data("status");
        if (_status != "新建") {
            Confirm.show(
                "提示",
                "您选中的记录中包含已经进入审批流程的选项，无法进行删除操作！！", {
                    确定: {
                        primary: true,
                        callback: function() {
                            Confirm.hide();
                        }
                    }
                }
            );
            objAll.prop("checked", false);
            obj.find("input[type=checkbox]:checked").each(function() {
                $(this).prop("checked", false);
            });
            arrCheck = undefined;
            return false;
        }
        var _id = $(this).data("id");
        arrCheck.push(_id);
    });
    if (arrCheck == undefined) {
        return;
    }
    if (arrCheck && arrCheck.length > 0) {
        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                width: 30,
                callback: function() {
                    var param = { ids: arrCheck.join(",") };
                    $.ajax({
                        type: "post",
                        url: url, //请求列表接口
                        data: param, //传入组装的参数
                        dataType: "json",
                        success: function(result) {
                            if (result.code == 200) {
                                Confirm.hide();
                                layer.msg("删除成功", {
                                    time: 2000
                                });
                                dataTable.ajax.reload();
                            } else {
                                layer.msg("删除失败", {
                                    time: 2000
                                });
                            }
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    } else {
        Confirm.show("提示", "请选择需要删除的选项！！", {
            确定: {
                primary: true,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    }
}
/**
 *  obj 当前被惦记单选对象
 *  url 删除接口路径
 *  dataTable 表格对象
 */
function deleteSingleWithStatus(obj, url, dataTable) {
    //判断元素的状态是否处于可以删除状态
    var _ids = obj.data("id");
    if (!_ids) {
        Confirm.show(
            "提示",
            "您选中的记录中包含已经进入审批流程的选项，无法进行删除操作！！", {
                确定: {
                    primary: true,
                    callback: function() {
                        Confirm.hide();
                    }
                }
            }
        );
    } else {
        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                width: 30,
                callback: function() {
                    var param = { ids: _ids };
                    $.ajax({
                        type: "post",
                        url: url, //请求列表接口
                        data: param, //传入组装的参数
                        dataType: "json",
                        success: function(result) {
                            if (result.code == 200) {
                                Confirm.hide();
                                layer.msg("删除成功", {
                                    time: 2000
                                });
                                dataTable.ajax.reload();
                            } else {
                                layer.msg("删除失败");
                            }
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    }
}

/*
 * 删除选中行方法
 * obj 子行checkbox选择器元素
 * url 对应的删除接口url地址
 * dataTables 定义的dataTables元素变量
 */
//status ==200
function deleteFun1(obj, url, dataTable, checkedIDS) {
    var checkedIDLen = checkedIDS.length;
    if (checkedIDLen == 0) {
        Confirm.show("提示", "请选择删除项", {
            确定: {
                primary: true,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    } else {
        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                callback: function() {
                    $.ajax({
                        type: "get",
                        url: url,
                        data: { ids: checkedIDS },
                        dataType: "json",
                        success: function(json) {
                            console.log("====/", json);
                            if (json.code == 200) {
                                Confirm.hide();
                                dataTable.ajax.reload();
                            }
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    }
}
/*删除一行供应商数据
 * obj 子行删除元素
 * url 对应删除接口地址
 * 返回 状态为code
 * 无工作流的一行删除
 */
function delectLineCode(obj, url) {
    $(document).delegate(obj, "click", function() {
        var userId = $(this).attr("data-id");
        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                callback: function() {
                    $.ajax({
                        type: "get",
                        url: url,
                        data: { ids: userId },
                        dataType: "json",
                        success: function(json) {
                            console.log("====/", json);
                            if (json.code == 200) {
                                Confirm.hide();
                                window.location.reload();
                            }
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
        //	$.ajax({
        //		type:"get",
        //		url:"/haocang-vendor-web/basisVendor/deleteMultiple",
        //		data:{ids:userId},
        //		async:true,
        //		success: function(json){
        //
        //			console.log("success",json);
        //			window.location.reload();
        //		},
        //		error:function(err){
        //			console.log(err);
        //		}
        //	});
    });
}

/*删除一行供应商数据
 * obj 子行删除元素
 * url 对应删除接口地址
 * 返回 状态为status
 */

/*删除一行供应商数据
 * obj 子行删除元素
 * url 对应删除接口地址
 * 返回 状态为status
 */
function labdelectLine(obj, url) {
    $(document).delegate(obj, "click", function() {
        var arrId = [];
        var userId = $(this).attr("data-id");
        //将取到的id push到数组中
        arrId.push(userId);
        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                callback: function() {
                    $.ajax({
                        type: "get",
                        url: url,
                        data: { ids: arrId },
                        dataType: "json",
                        success: function(json) {
                            console.log("====/", json);
                            if (json.status == 200) {
                                Confirm.hide();
                                window.location.reload();
                            }
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    });
}

function delectLineSupplier(obj, url) {
    $(document).delegate(obj, "click", function() {
        var userId = $(this).attr("data-id");
        var statusId = $(this).attr("data-status");
        if (statusId != 1) {
            Confirm.show("提示", "确认删除？", {
                确定: {
                    primary: true,
                    callback: function() {
                        $.ajax({
                            type: "get",
                            url: url,
                            data: { ids: userId },
                            dataType: "json",
                            success: function(json) {
                                console.log("====/", json);
                                if (json.status == 200) {
                                    Confirm.hide();
                                    window.location.reload();
                                }
                            },
                            error: function(e) {
                                console.log(e);
                            }
                        });
                    }
                },
                取消: {
                    primary: false,
                    callback: function() {
                        Confirm.hide();
                    }
                }
            });
        } else {
            Confirm.show("提示", "该供应商无法删除！", {
                确定: {
                    primary: true,
                    callback: function() {
                        Confirm.hide();
                    }
                }
            });
        }
    });
}
//删除提示(含涉及后台)
function delectPoint(obj, url) {
    $(document).delegate(obj, "click", function() {
        var That = $(this);
        var localId = $(this)
            .parent()
            .attr("data-id");
        var localsubId = $(this)
            .prev()
            .attr("data-id");
        var subId =
            $(this)
            .prev()
            .attr("data-id") != undefined ?
            $(this)
            .prev()
            .attr("data-id") :
            $(this)
            .parent()
            .attr("data-id");

        debugger;

        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                callback: function() {
                    if (localId == "null") {
                        debugger;
                        That.parents(".purchaseList").remove();
                        Confirm.hide();
                    } else if (localsubId == "null") {
                        debugger;
                        That.parents("li").remove();
                        Confirm.hide();
                    } else {
                        debugger;
                        $.ajax({
                            type: "get",
                            url: url + "?id=" + subId,
                            async: true,
                            success: function(data) {
                                Confirm.hide();
                                window.location.reload();
                            },
                            error: function(res) {
                                console.log(res);
                            }
                        });
                    }
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    });
}
/*删除一行供应商数据
 * obj 子行删除元素
 * url 对应删除接口地址
 * 返回 状态为code ==200
 * 采购有工作流删除一行
 */
function delectLineS(obj, url) {
    //删除一行供应商数据
    $(document).delegate(obj, "click", function() {
        var userId = $(this).attr("data-id");
        var procinstid = $(this).attr("data-procinstid");
        var appliy = $(this).attr("data-appliy");

        if (
            procinstid == "undefined" ||
            procinstid == undefined ||
            appliy == "申请人提交"
        ) {
            Confirm.show("提示", "确认删除？", {
                确定: {
                    primary: true,
                    callback: function() {
                        $.ajax({
                            type: "get",
                            url: url,
                            data: { ids: userId },
                            dataType: "json",
                            success: function(json) {
                                console.log("====/", json);
                                if (json.code == 200 || json.status == 200) {
                                    Confirm.hide();
                                    window.location.reload();
                                }
                            },
                            error: function(e) {
                                console.log(e);
                            }
                        });
                    }
                },
                取消: {
                    primary: false,
                    callback: function() {
                        Confirm.hide();
                    }
                }
            });
        } else {
            Confirm.show("提示", "该工单已进入流程,不能中途删除！", {
                确定: {
                    primary: true,
                    callback: function() {
                        Confirm.hide();
                    }
                }
            });
        }
    });
}
//删除单行数据(不带工作流)
function delectProject(obj, url) {
    //删除一行供应商数据
    $(document).delegate(obj, "click", function() {
        var userId = $(this).attr("data-id");
        debugger;
        Confirm.show("提示", "确认删除？", {
            确定: {
                primary: true,
                callback: function() {
                    $.ajax({
                        type: "get",
                        url: url + "/" + userId,
                        dataType: "json",
                        success: function(json) {
                            console.log("====/", json);
                            if (json.status == 200) {
                                Confirm.hide();
                                window.location.reload();
                            }
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            },
            取消: {
                primary: false,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    });
}
/*
 * 删除选中行方法（只能删除新建的单子）
 * obj 子行checkbox选择器元素
 * url 对应的删除接口url地址
 * dataTables 定义的dataTables元素变量
 */
function deleteNewFun(obj, url, dataTable) {
    var checkedIdsNew = "";
    var checkedIdsOther = "";
    obj.each(function(i, n) {
        if (
            $(n)
            .find("input[type=checkbox]")
            .is(":checked")
        ) {
            if (
                $(n)
                .find(".status")
                .text() == "新建"
            ) {
                checkedIdsNew +=
                    ",," +
                    $(n)
                    .find("input[type=checkbox]")
                    .attr("data-id");
            } else {
                checkedIdsOther += $(n)
                    .find("input[type=checkbox]")
                    .attr("data-id");
            }
        }
    });
    if (checkedIdsNew == "" && checkedIdsOther == "") {
        Confirm.show("提示", "请选择删除项", {
            确定: {
                primary: true,
                callback: function() {
                    Confirm.hide();
                }
            }
        });
    } else {
        if (
            (checkedIdsNew.length > 1 && checkedIdsOther.length > 0) ||
            (checkedIdsNew == "" && checkedIdsOther.length > 0)
        ) {
            Confirm.show("提示", "只能删除新建项", {
                确定: {
                    primary: true,
                    callback: function() {
                        Confirm.hide();
                    }
                }
            });
        } else {
            Confirm.show("提示", "确认删除？", {
                确定: {
                    primary: true,
                    callback: function() {
                        $.ajax({
                            type: "post",
                            url: url,
                            data: { ids: checkedIdsNew },
                            dataType: "json",
                            success: function(json) {
                                if (json.code == 200) {
                                    Confirm.hide();
                                    dataTable.ajax.reload();
                                } else {
                                    if (json.MSG != "") {
                                        showErrorMsg(json.MSG);
                                    }
                                }
                            },
                            error: function(e) {
                                console.log(e);
                            }
                        });
                    }
                }
            });
        }
    }
}

/*
 * 详细页ajax渲染数据方法
 * urlName 某模块url地址名字
 * indexID 每条数据ID号
 * templateScript 模板引擎ID名字
 * templateEle 模板引擎展示内容的元素选择器
 */
function initQsualityDetail(urlName, ID, templateScript, templateEle) {
    $.ajax({
        type: "get",
        url: urlName,
        data: { id: ID },
        dataType: "json",
        success: function(json) {
            userInfo = json.DATA.entry;
            var html = template(templateScript, userInfo);
            templateEle.html(html);
        },
        error: function(e) {
            console.log(e);
        }
    });
}

//加载筛选条件
function queryAdd(url, element, type) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            console.log(json);
            debugger;
            if (type == 1) {
                if (json.code == 200) {
                    var itemsArr = json.DATA.items;
                    console.log(itemsArr);
                    console.log(typeof itemsArr);
                    itemsArr.unshift({
                        name: "全部"
                    });
                    $.each(itemsArr, function(index, ele) {
                        if (ele.name == "全部") {
                            var html =
                                "<label class='mark mark-selected'>" +
                                ele.name +
                                "<input type='hidden' value='" +
                                ele.id +
                                "'></label>";
                            element.append(html);
                        } else {
                            var html =
                                "<span class='mark'>" +
                                ele.name +
                                "<input type='hidden' value='" +
                                ele.id +
                                "'></span>";
                            element.append(html);
                        }
                    });
                }
            } else if (type == "className") {
                if (json.code == 200) {
                    $.each(json.DATA.items.list, function(index, ele) {
                        var html =
                            "<span class='mark'>" +
                            ele.className +
                            "<input type='hidden' value='" +
                            ele.aid +
                            "'></span>";
                        element.append(html);
                    });
                }
            } else if (type == "userName") {
                if (json.code == 200) {
                    $.each(json.DATA.items, function(index, ele) {
                        var html =
                            "<span class='mark'>" +
                            ele.userName +
                            "<input type='hidden' value='" +
                            ele.creater +
                            "'></span>";
                        element.append(html);
                    });
                }
            } else if (type == "orgName") {
                if (json.code == 200) {
                    $.each(json.DATA.items, function(index, ele) {
                        var html =
                            "<span class='mark'>" +
                            ele.orgName +
                            "<input type='hidden' value='" +
                            ele.orgId +
                            "'></span>";
                        element.append(html);
                    });
                }
            } else {
                if (json.RESULT == "success") {
                    $.each(json.DATA.list, function(index, ele) {
                        var html =
                            "<span class='mark'>" +
                            ele.name +
                            "<input type='hidden' value='" +
                            ele.aid +
                            "'></span>";
                        element.append(html);
                    });
                }
            }
        }
    });
}

//状态动态添加code
function queryAddStatus(url, element) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            console.log("json--------", json);
            json.DATA.status.all = "全部";
            if (json.code == 200) {
                $.each(json.DATA.status, function(index, ele) {
                    if (ele == "全部") {
                        var html = "<label class='mark mark-selected'>" + ele + "</label>";
                        element.prepend(html);
                    } else {
                        var html = "<span class='mark'>" + ele + "</span>";
                        element.append(html);
                    }
                });
            }
        }
    });
}
//库存报警
function queryAddWarn1(url, element) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            console.log("json--------", json);
            json.DATA.items.unshift({ name: "全部", id: "0" });
            if (json.code == 200) {
                $.each(json.DATA.items, function(index, ele) {
                    if (ele.name == "全部") {
                        var html =
                            "<label class='mark mark-selected'>" + ele.name + "</label>";
                        element.prepend(html);
                    } else {
                        var html = "<span class='mark'>" + ele.name + "</span>";
                        element.append(html);
                    }
                });
            }
        }
    });
}

function queryAddWarn2(url, element) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            debugger;
            console.log("json--------", json);

            if (json.status == 200) {
                var _data = json.data.list;
                _data.push({
                    className: "全部",
                    id: null
                });
                $.each(json.data.list, function(index, ele) {
                    if (ele.className == "全部") {
                        var html =
                            "<label class='mark mark-selected'>" + ele.className + "</label>";
                        element.prepend(html);
                    } else {
                        var html = "<span class='mark'>" + ele.className + "</span>";
                        element.append(html);
                    }
                });
            }
        }
    });
}

//设备管理系统项目状态
function eqgetAddStatus(url, element) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            if (json.status == 200) {
                var dataArr = [];
                dataArr = json.data.list;
                dataArr.push({ className: "全部", clientId: null });
                console.log(dataArr);
                $.each(dataArr, function(index, ele) {
                    if (ele.className == "全部") {
                        var html =
                            "<label class='mark mark-selected' data-id=" +
                            ele.clientId +
                            ">" +
                            ele.className +
                            "</label>";
                        element.prepend(html);
                    } else {
                        var html =
                            "<span class='mark' data-id=" +
                            ele.clientId +
                            ">" +
                            ele.className +
                            "</span>";
                        element.append(html);
                    }
                });
            }
        },
        error: function(res) {
            console.log(res);
            debugger;
        }
    });
}
//工程管理系统项目状态
function getAddStatus(url, element) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            var dataArr = [];
            dataArr = json.data.list;
            dataArr.push({ dataValue: "全部", dataKey: null });
            console.log(dataArr);
            if (json.status == 200) {
                $.each(dataArr, function(index, ele) {
                    if (ele.dataValue == "全部") {
                        var html =
                            "<label class='mark mark-selected' data-id=" +
                            ele.dataKey +
                            ">" +
                            ele.dataValue +
                            "</label>";
                        element.prepend(html);
                    } else {
                        var html =
                            "<span class='mark' data-id=" +
                            ele.dataKey +
                            ">" +
                            ele.dataValue +
                            "</span>";
                        element.append(html);
                    }
                });
            }
        },
        error: function(res) {
            console.log(res);
            debugger;
        }
    });
}
//监测点
function getAddStatus(url, element) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            var dataArr = [];
            dataArr = json.data.list;
            dataArr.push({ dataValue: "全部", dataKey: null });
            console.log(dataArr);
            if (json.status == 200) {
                $.each(dataArr, function(index, ele) {
                    if (ele.dataValue == "全部") {
                        var html =
                            "<label class='mark mark-selected' data-id=" +
                            ele.dataKey +
                            ">" +
                            ele.dataValue +
                            "</label>";
                        element.prepend(html);
                    } else {
                        var html =
                            "<span class='mark' data-id=" +
                            ele.dataKey +
                            ">" +
                            ele.dataValue +
                            "</span>";
                        element.append(html);
                    }
                });
            }
        },
        error: function(res) {
            console.log(res);
            debugger;
        }
    });
}
//状态动态添加status==200
function queryAddStatus1(url, element) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            if (json.status == 200) {
                console.log("2222222", json.data.list);
                $.each(json.data.list, function(index, ele) {
                    var html = "<span class='mark'>" + ele.className + "</span>";
                    element.append(html);
                });
            }
        }
    });
}

//状态动态添加status==200(供应商形态分类)
function queryAddStatusValue(url, element) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            if (json.status == 200) {
                var _data = json.data.list;
                _data.push({
                    className: "全部",
                    id: null
                });
                $.each(json.data.list, function(index, ele) {
                    if (ele.className == "全部") {
                        var html =
                            "<label class='mark mark-selected' data-id='" +
                            ele.id +
                            "'>" +
                            ele.className +
                            "</label>";
                        element.prepend(html);
                    } else {
                        var html =
                            "<span class='mark' data-id='" +
                            ele.id +
                            "'>" +
                            ele.className +
                            "</span>";
                        element.append(html);
                    }
                });
            }
        }
    });
}
//供应商类型隐藏传值(id)
function queryAddStatusValue2(url, element) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            var dataJson = json.data.list;
            dataJson.unshift({
                className: "全部",
                id: null
            });
            if (json.status == 200) {
                $.each(dataJson, function(index, ele) {
                    if (ele.className == "全部") {
                        var html =
                            "<label class='mark mark-selected' data-id='" +
                            ele.id +
                            "'>" +
                            ele.className +
                            "</label>";
                        element.append(html);
                    } else {
                        var html =
                            "<span class='mark' data-id='" +
                            ele.id +
                            "'>" +
                            ele.className +
                            "</span>";
                        element.append(html);
                    }
                });
            }
        }
    });
}
//状态动态添加status==200
function queryAddStatus2(url, element) {
    $.ajax({
        type: "get",
        url: url, //请求列表接口
        dataType: "json",
        success: function(json) {
            if (json.status == 200) {
                json.data["0"] = "全部";
                var _data = json.data;
                for (var key in _data) {
                    if (key == 0) {
                        var html =
                            "<label class='mark mark-selected' data-id='" +
                            key +
                            "'>" +
                            _data[key] +
                            "</span>";
                        element.prepend(html);
                    } else {
                        var html =
                            "<span class='mark' data-id='" +
                            key +
                            "'>" +
                            _data[key] +
                            "</span>";
                        element.append(html);
                    }
                }
            }
        }
    });
}
/**
 * 获取指定的URL参数值
 */
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

/**
 * 字符串中文字符串
 */
function toUtf8(str) {
    var out, i, len, c;
    out = "";
    len = str.length;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if (c >= 0x0001 && c <= 0x007f) {
            out += str.charAt(i);
        } else if (c > 0x07ff) {
            out += String.fromCharCode(0xe0 | ((c >> 12) & 0x0f));
            out += String.fromCharCode(0x80 | ((c >> 6) & 0x3f));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f));
        } else {
            out += String.fromCharCode(0xc0 | ((c >> 6) & 0x1f));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f));
        }
    }
    return out;
}

//获取隐藏域值，并添加效果
function getValueFun(obj, ele, markValue) {
    if (obj.parent().hasClass(ele)) {
        if (obj.text() == "全部") {
            if (obj.hasClass("mark-selected")) {
                markValue = "undefined";
            } else {
                obj.addClass("mark-selected");
                obj
                    .parent()
                    .find("span")
                    .removeClass("mark-selected");
                markValue = "undefined";
            }
        } else {
            obj
                .parent()
                .find("label")
                .removeClass("mark-selected");
            if (obj.hasClass("mark-selected")) {
                obj.removeClass("mark-selected");
                markValue = markValue.replace(obj.find("input").val() + ",", "");
            } else {
                if (markValue.indexOf("undefined") > -1) {
                    markValue = "";
                    obj.addClass("mark-selected");
                    markValue += obj.find("input").val() + ",";
                } else {
                    obj.addClass("mark-selected");
                    markValue += obj.find("input").val() + ",";
                }
            }
        }
    }
    return markValue;
}

//监测点枚举查询(传id)
function getMonitorValueFun(obj, ele, markValue, isRadio) {
    if (obj.parent().hasClass(ele)) {
        if (obj.attr("data-id") == "undefined") {
            if (obj.hasClass("mark-selected")) {
                markValue = "undefined";
            } else {
                obj.addClass("mark-selected");
                obj
                    .parent()
                    .find("span")
                    .removeClass("mark-selected");
                markValue = "undefined";
            }
        } else {
            obj
                .parent()
                .find("label")
                .removeClass("mark-selected");
            if (obj.hasClass("mark-selected")) {
                obj.removeClass("mark-selected");

                let _True = obj
                    .parent()
                    .find("span")
                    .hasClass("mark-selected");
                if (!_True) {
                    obj
                        .parent()
                        .find("label")
                        .addClass("mark-selected");
                }
                markValue = markValue.replace(obj.attr("data-id") + ",", "");
            } else {
                if (markValue.indexOf("undefined") > -1) {
                    markValue = "";
                    obj.addClass("mark-selected");
                    markValue += obj.attr("data-id") + ",";
                } else {
                    if (isRadio) {
                        obj
                            .addClass("mark-selected")
                            .siblings("span")
                            .removeClass("mark-selected");
                        markValue = "";
                        markValue += obj.attr("data-id") + ",";
                    } else {
                        obj.addClass("mark-selected");
                        markValue += obj.attr("data-id") + ",";
                    }
                }
            }
        }
    }
    return markValue;
}
//获取值，并添加效果
function getTextFun(obj, ele, mark) {
    if (obj.parent().hasClass(ele)) {
        if (obj.text() == "全部") {
            if (obj.hasClass("mark-selected")) {
                mark = "全部";
            } else {
                obj.addClass("mark-selected");
                obj
                    .parent()
                    .find("span")
                    .removeClass("mark-selected");
                mark = "全部";
            }
        } else {
            obj
                .parent()
                .find("label")
                .removeClass("mark-selected");
            if (obj.hasClass("mark-selected")) {
                obj.removeClass("mark-selected");
                let _True = obj
                    .parent()
                    .find("span")
                    .hasClass("mark-selected");
                if (!_True) {
                    obj
                        .parent()
                        .find("label")
                        .addClass("mark-selected");
                }
                mark = mark.replace("'" + obj.text() + "',", "");
            } else {
                if (mark.indexOf("全部") > -1) {
                    mark = "";
                    obj.addClass("mark-selected");
                    mark += "'" + obj.text() + "',";
                } else {
                    obj.addClass("mark-selected");
                    mark += "'" + obj.text() + "',";
                }
            }
        }
    }
    return mark;
}

//获data中的id值，并添加效果
function getDataFun(obj, ele, mark) {
    debugger;
    if (obj.parent().hasClass(ele)) {
        if (obj.text() == "全部") {
            if (obj.hasClass("mark-selected")) {
                mark = "全部";
            } else {
                obj.addClass("mark-selected");
                obj
                    .parent()
                    .find("span")
                    .removeClass("mark-selected");
                mark = "全部";
            }
        } else {
            obj
                .parent()
                .find("label")
                .removeClass("mark-selected");
            if (obj.hasClass("mark-selected")) {
                obj.removeClass("mark-selected");
                let _True = obj
                    .parent()
                    .find("span")
                    .hasClass("mark-selected");
                if (!_True) {
                    obj
                        .parent()
                        .find("label")
                        .addClass("mark-selected");
                }
                mark = mark.replace("" + obj.data("id"), "");
            } else {
                if (mark.indexOf("全部") > -1) {
                    mark = "";
                    obj.addClass("mark-selected");
                    mark += "" + obj.data("id");
                } else {
                    obj.addClass("mark-selected");
                    mark += "" + obj.data("id");
                }
            }
        }
    }
    return mark;
}

function getTextFun2(obj, ele, mark) {
    if (obj.parent().hasClass(ele)) {
        if (obj.attr("data-id") == "null") {
            if (obj.hasClass("mark-selected")) {
                mark = "null";
            } else {
                obj.addClass("mark-selected");
                obj
                    .parent()
                    .find("span")
                    .removeClass("mark-selected");
                mark = "null";
            }
        } else {
            obj
                .parent()
                .find("label")
                .removeClass("mark-selected");
            if (obj.hasClass("mark-selected")) {
                obj.removeClass("mark-selected");
                mark = mark.replace("'" + obj.attr("data-id") + "',", "");
                debugger;
                if (!mark) {
                    obj
                        .parent()
                        .find("label")
                        .addClass("mark-selected");
                    mark = "null";
                }
            } else {
                if (mark.indexOf("null") > -1) {
                    mark = "";
                    obj.addClass("mark-selected");
                    mark += "'" + obj.attr("data-id") + "',";
                } else {
                    obj.addClass("mark-selected");
                    mark += "'" + obj.attr("data-id") + "',";
                }
            }
        }
    }
    return mark;
}
//通过供应商状态传值(1,2,3)
function getStatusFun2(obj, ele, mark) {
    if (obj.parent().hasClass(ele)) {
        if (obj.attr("data-id") == "0") {
            if (obj.hasClass("mark-selected")) {
                mark = "0";
            } else {
                obj.addClass("mark-selected");
                obj
                    .parent()
                    .find("span")
                    .removeClass("mark-selected");
                mark = "0";
            }
        } else {
            obj
                .parent()
                .find("label")
                .removeClass("mark-selected");
            if (obj.hasClass("mark-selected")) {
                obj.removeClass("mark-selected");
                mark = mark.replace("'" + obj.attr("data-id") + "',", "");
            } else {
                if (mark.indexOf("0") > -1) {
                    mark = "";
                    obj.addClass("mark-selected");
                    mark += "'" + obj.attr("data-id") + "',";
                } else {
                    obj.addClass("mark-selected");
                    mark += "'" + obj.attr("data-id") + "',";
                }
            }
        }
    }
    return mark;
    //  if(obj.parent().hasClass(ele)){
    //      if(obj.hasClass("mark-selected")){
    //          obj.removeClass("mark-selected");
    //          mark=mark.replace("'"+obj.attr("data-id")+"',",'');
    //      }else{
    //          obj.addClass("mark-selected");
    //          mark+="'"+obj.attr("data-id")+"',";
    //      }
    //  }
    //  return mark;
}
//获取cookie中数据,判断用户是否登录
//function getCookie() {
//  userInfo = document.cookie;
//  var userInfoArray = userInfo.split(";");
//  for(var i = 0; i < userInfoArray.length; i++) {
//      if(userInfoArray[i].indexOf("HC_TOKEN") > -1) {
//          var num = userInfoArray[i].indexOf("=") + 1;
//          console.log(num)
//          if(num != "" || num != undefined) {
//              userName = userInfoArray[i].slice(num);
//              return userName;
//          } else if(num == 9) {
//              userName == false;
//          }
//      }
//  }
//}
var userId;
var userName;

function getMaxCookie() {
    userInfo = document.cookie;

    console.log(userInfo, "-------");
    // debugger;
    var userInfoArray = userInfo.split(";");
    for (var i = 0; i < userInfoArray.length; i++) {
        if (userInfoArray[i].indexOf("HC_TOKEN") > -1) {
            var num = userInfoArray[i].indexOf("=") + 1;
            console.log(num);

            if (num != "" || num != undefined) {
                userName = userInfoArray[i].slice(num);
                getUserName(userName);
                return userName;
                debugger;
            } else if (num == 9) {
                userName == false;
            }
        }
    }
}

function getUserName() {
    $.ajax({
        type: "get",
        url: SSO_URL + "/user/token/" + userName,
        dataType: "jsonp",
        async: true,
        success: function(result) {
            var data = result.data;
            console.log("data---->>", data);
            sessionStorage.setItem("uId", data.id);
            sessionStorage.setItem("uName", data.username);
            sessionStorage.setItem("pass", data.password);
            userId = data.username;
            console.log("userId--", userId);
            console.log(data.organizeId);
            localStorage.setItem("currentId", data.organizeId);
            return userId;
        },
        error: function(data) {
            console.log("报错了--------", data);
        }
    });
}

//打开和关闭切换效果
function toogleQuery(obj) {
    if (obj.hasClass("eye-open")) {
        obj.removeClass("eye-open").addClass("eye-close");
        obj.css(
            "background",
            "url(/max-common-web/images/icon_up.png) center center no-repeat"
        );
    } else {
        obj.removeClass("eye-close").addClass("eye-open");
        obj.css(
            "background",
            "url(/max-common-web/images/icon_down.png) center center no-repeat"
        );
    }
    $(".query-list").slideToggle();
}

/*
 * 根据接口赋值select
 * objOption 元素的option
 * jsonName 接口值
 * hiddenId 隐藏的元素
 * obj 元素
 */
function getValueByJson(objOption, jsonName, hiddenId, obj) {
    objOption.each(function() {
        if ($(this).attr("value") == jsonName) {
            $(this).attr("selected");
            obj.val($(this).val());
            hiddenId.val($(this).attr("value"));
        }
    });
}

/*
 * 加载审批日志
 * url 日志加载地址
 * obj 隐藏的ID元素
 * orderType type参数
 */
function initQsualityInLog(url, obj, orderType) {
    var orderId = obj.val();
    var orderType = orderType;
    $.ajax({
        type: "get",
        url: url,
        data: { orderId: orderId, orderType: orderType },
        dataType: "json",
        success: function(json) {
            $("#transferLog tbody").html("");
            $.each(json.DATA.items, function(index, ele) {
                var html = "";
                html += "<tr><td>" + ele.task + "</td>";
                html += "<td>" + ele.name + "</td>";
                html += "<td>" + ele.result + "</td>";
                html +=
                    "<td>" + (ele.remarks == undefined ? "" : ele.remarks) + "</td>";
                html += "<td>" + ele.timestamp + "</td></tr>";
                $("#transferLog tbody").append(html);
            });
        }
    });
}
/*
 * 打开流程模型模态框
 */
function openModelDialog(type) {
    //编辑流程模型
    $("#editFlow").click(function() {
        console.log(type);
        debugger;
        if ("noModelKey" != getModelKeyByType(type)) {
            //显示模态框
            $("#flowModal").modal("show");
            //				//.css({"width":w_+"px";"height":h_+"px"});
            //				$("#flowModal").replace("",'')
            //流程模型页面
            $(".modal-body #flowIframe").attr(
                "src",
                ACTIVITI_URL +
                "modeler.html?flag=1&modelKey=" +
                getModelKeyByType(type)["key"]
            );
        } else {
            alert("未配置对应的流程模型!");
        }
    });
}

/*
 * 关闭流程模型模态框
 */
function closeModelDialog() {
    $("#flowModal").modal("hide");
}

/*
 *各模块对应流程模型的key值,统一设置
 */
function getModelKeyByType(type) {
    //模块类别(定死了不要改):流程模型key(来源于具体模型定义时的key值)
    var map = {
        Report: { key: "zf_report", name: "检测报告" },
        Entrust: { key: "zf_entrust", name: "委托单" },
        Proposal: { key: "zf_proposal", name: "合理化建议" },
        EHS: { key: "zf_ehs", name: "EHS检查" },
        Surprise: { key: "zf_surprise", name: "吃惊工单" },
        Proposal: { key: "zf_proposal", name: "合理化建议" },
        Ehs: { key: "zf_ehs", name: "5S-EHS检查" },
        Surprise: { key: "zf_surprise", name: "吃惊工单" },
        PurchaseRequest: { key: "zf_purchaseRequest", name: "采购申请单" },
        PurchasePlanOuter: {
            key: "zf_purchasePlanOuter",
            name: "采购计划外申请单"
        },
        PurchaseMonthPlan: { key: "zf_purchaseMonthPlan", name: "采购月度计划单" },
        PurchaseOrder: { key: "zf_purchaseOrder", name: "采购订单" },
        PurchasePrice: { key: "zf_purchasePrice", name: "议价比价" },
        Contract: { key: "zf_contract", name: "采购合同" },
        InStore: { key: "zf_inStore", name: "入库管理" },
        OutStore: { key: "zf_outStoreTwo", name: "出库管理" },
        InventoryCheck: { key: "zf_inventoryCheck", name: "盘点管理" },
        InventoryAllot: { key: "zf_inventoryAllot", name: "调拨管理" }
    };
    if (undefined != type && undefined != map[type]) {
        return map[type];
    } else {
        return { key: "noModelKey", name: "" };
    }
}

//错误提示
function showErrorMsg(msg) {
    $("body").toast({
        content: msg,
        duration: 3000
    });
}

//获取浏览器可视高度
function getScrollTop() {
    var $Height = $("body").scrollTop();
    console.log("$Height===>", $Height);
}

function jalert(s, w, h) {
    var _w = w ? w : 200,
        _h = h ? h : 100,
        _left = _w / 2,
        _top = _h / 2;
    if ($(".jalert").length == 0) {
        $('<div class="jalert" />', {})
            .css({
                width: _w + "px",
                margin: "-" + _top + "px 0 0 -" + _left + "px",
                padding: "20px 5px"
            })
            .html(s)
            .appendTo($("body"));
        setTimeout(function() {
            $(".jalert").remove();
        }, 3000);
    }
}